package com.ruoyi.client.controller;

import com.ruoyi.client.BaseOpenController;
import com.ruoyi.common.constdef.ErrorDef;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.SpringContextUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.ClientUserService;
import com.ruoyi.system.domian.jpa.CdUserJpa;
import com.ruoyi.system.domian.service.CdUserService;
import com.ruoyi.common.utils.json.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Dale Mao    ---多多 Email:453918229@qq.com
 * @description LoginController
 * @date 2021-01-26 13:45
 */

@RestController
@RequestMapping("/open")
public class LoginController extends BaseOpenController {

    @Autowired
    ClientUserService clientUserService;

    @Autowired
    CdUserService cdUserService;

    @PostMapping(value = "/userlogin")
    public JsonResult userlogin(@RequestBody CdUserJpa cdUserJpa){


        CdUserJpa user =cdUserService.getUserInfo(cdUserJpa);


        if(StringUtils.isNull(user) || user.getStatus() != 1){
            return new JsonResult(ErrorDef.USER_ISFORBID,ErrorDef.MSG_USER_ISFORBID);
        }

        String token = clientUserService.login(cdUserJpa);
        user.setToken(token);
        return new JsonResult(100,"测试",user);
    }




}
